package org.iipg.common.data.advice;

import org.iipg.common.data.exception.PhException;
import org.iipg.common.data.vo.PhResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/** Author: zhuhy163@163.com Date: 2020/8/29 */
@ControllerAdvice
@RequiredArgsConstructor
public class ExceptionHandlerAdvice {

	@ExceptionHandler(PhException.class)
	@ResponseBody
	public PhResponse<String> handleTbException(PhException e) {
		PhResponse<String> ret = new PhResponse<>();
		ret.setCode(e.getErrorCode());
		ret.setData("");
		ret.setMessage(e.getMessage());
		return ret;
	}

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public PhResponse<String> handleException(Exception e) {
		PhResponse<String> ret = new PhResponse<>();
		ret.setCode(500);
		ret.setData("");
		ret.setMessage(e.getMessage());
		return ret;
	}

}
